// Cable_TXG at http://meltingpot.fortunecity.com/guadelupe/10 // Short Url: htpp://clik.to/DigitalWorld #include <iostream> #include <stdlib> #include "cppfunc.h" // Remove this header file (Random() inside, courtesy of Victor Bazarov // at alt.comp.lang.learn.c-c++ News Group posting. Neat function! :-) using namespace std; template<typename T> void quick_sort(T array[], int first, int last) { T temp; T list_seperator; int low, high; low = first; high = last; list_seperator = array[(first + last)/2]; do { while(array[low] < list_seperator) low++; while(array[high] > list_seperator) high--; if(low <= high) { temp = array[low]; array[low++] = array[high]; array[high--] = temp; } }while(low <= high); if(first < high) quick_sort(array, first, high); if(low < last) quick_sort(array, low, last); } /**** Decomment this line to use Random() from cppfunc.h template<typename T> T Random(T top) { return T( (double(rand()) * (top + 1)) / (double(RAND_MAX) + 1) ); } ****/ int main(void) { int values[100], i; float fvalues[100]; char cvalues[100]; for(i = 0; i < 100; i++) { values[i] = Random(100); fvalues[i] = Random((float)100.0); cvalues[i] = Random(255); } quick_sort(values, 0, 99); quick_sort(fvalues, 0, 99); for(i = 0; i < 100; i++) cout << values[i] << " "; std::cout << endl; for(i = 0; i < 100; i++) std::cout << fvalues[i] << " "; for(i = 0; i < 100; i++) std::cout << cvalues[i] << " "; return 0; }